﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orders.Entities;
using CreateShared.Orders_Module.Interface.Services;

namespace CreateShared.Orders_Module.Services
{
    public class OrderService : IOrderService
    {
        List<Order> _orders = new List<Order>();

        public OrderService()
        {
            // create dummy orders
            _orders.Add(new Order() { CustomerReference = "My first order", OrderDate = DateTime.Now.AddMonths(1), OrderNo = "0001" });
            _orders.Add(new Order() { CustomerReference = "My second order", OrderDate = DateTime.Now.AddMonths(2), OrderNo = "0002" });
            _orders.Add(new Order() { CustomerReference = "My third order", OrderDate = DateTime.Now.AddMonths(3), OrderNo = "0003" });
            _orders.Add(new Order() { CustomerReference = "My fourth order", OrderDate = DateTime.Now.AddMonths(4), OrderNo = "0004" });
            // add some order rows to the created orders
            _orders[0].OrderRows = new List<OrderRow>();
            _orders[0].OrderRows.Add(new OrderRow() { Description = "Lobster", Price = 9.99M, Quantity = 4 });
            _orders[0].OrderRows.Add(new OrderRow() { Description = "Clams", Price = 2.99M, Quantity = 20 });
            _orders[0].OrderRows.Add(new OrderRow() { Description = "Salmon", Price = 4.99M, Quantity = 2 });

            _orders[1].OrderRows = new List<OrderRow>();
            _orders[1].OrderRows.Add(new OrderRow() { Description = "Bass", Price = 9.99M, Quantity = 4 });
            _orders[1].OrderRows.Add(new OrderRow() { Description = "Lobster", Price = 9.99M, Quantity = 6 });
            _orders[1].OrderRows.Add(new OrderRow() { Description = "Tuna", Price = 6.99M, Quantity = 3 });

            _orders[2].OrderRows = new List<OrderRow>();
            _orders[2].OrderRows.Add(new OrderRow() { Description = "Shrimps", Price = 1.99M, Quantity = 40 });
            _orders[2].OrderRows.Add(new OrderRow() { Description = "Oysters", Price = 2.99M, Quantity = 12 });
            _orders[2].OrderRows.Add(new OrderRow() { Description = "Salmon", Price = 4.99M, Quantity = 2 });

            _orders[3].OrderRows = new List<OrderRow>();
            _orders[3].OrderRows.Add(new OrderRow() { Description = "Crab", Price = 3.99M, Quantity = 4 });
            _orders[3].OrderRows.Add(new OrderRow() { Description = "Tuna", Price = 6.99M, Quantity = 10 });
            _orders[3].OrderRows.Add(new OrderRow() { Description = "Salmon", Price = 4.99M, Quantity = 2 });
        }

        public IList<Order> RetrieveOrders()
        {
            return _orders;
        }

        public IList<OrderRow> RetrieveOrderRows(string orderNo)
        {
            return _orders.Single<Order>(o => o.OrderNo == orderNo).OrderRows;
        }
    }
}
